package com.tony.study.thread.sync;

import java.util.ArrayList;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 *
 * @Title: UnsafeList
 * @Auther: 皮蛋布丁
 * @Date: 2021/10/31/20:04
 * @Description: 线程不安全的集合(两个数值同时添加到同一个位置，就会覆盖掉)
 */
public class UnsafeList {

    public static void main(String[] args) {
        List<String> list = new ArrayList<>();
        for (int i = 0; i < 10000; i++) {
            new Thread(() -> {
                list.add(Thread.currentThread().getName());
            }).start();
        }
        try {
            Thread.sleep(3000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println(list.size());
    }
}
